#!/usr/bin/python2.5

# Copyright 2009 Ferdjaoui Sahid.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


import logging

from google.appengine.ext import db
from google.appengine.api import memcache



SLAP_STATUS = (
  'Princess Snow White...',                        # 0
  'Pfff, Newbie !',                                # 1 - 2
  'Ok, but you have yet to prove',                 # 3 - 8
  'Big hand ...hmm ?',                             # 9 - 20
  'A Marshall',                                    # 21 - 50
  'A Crazy Slapper !',                             # 51 - 100
  'Please stop that!, you want to kill us all',    # 101 - 200
  'I see a light',                                 # 200 - more
)


class CachingModel (db.Model):
  pass

class Actor (CachingModel):
  uid     = db.StringProperty ()
  created = db.DateTimeProperty (auto_now_add=True)
  count_sended   = db.IntegerProperty (default = 0);
  count_received = db.IntegerProperty (default = 0);

  def __init__ (self, parent=None, key_name=None, _app=None, **kw):
    self.status = self.my_status
    super (Actor, self).__init__(parent, key_name, _app, **kw)

  def my_status (self):
    if self.count_sended < 1:
      return SLAP_STATUS[0]
    if self.count_sended < 3:
      return SLAP_STATUS[1]
    if self.count_sended < 9:
      return SLAP_STATUS[2]
    if self.count_sended < 21:
      return SLAP_STATUS[3]
    if self.count_sended < 51:
      return SLAP_STATUS[4]
    if self.count_sended < 101:
      return SLAP_STATUS[5]
    if self.count_sended < 101:
      return SLAP_STATUS[6]
    return SLAP_STATUS[7]


class Entry (CachingModel):
  owner      = db.ReferenceProperty (Actor, collection_name = 'owner')
  target     = db.ReferenceProperty (Actor, collection_name = 'targer')
  comment    = db.StringProperty ()
  created_at = db.DateTimeProperty (auto_now_add=True)
